package com.yi.suprise.presenter;

import android.content.Context;

import com.yi.suprise.modle.MainModle;
import com.yi.suprise.response.MainResponse;
import com.yi.suprise.util.ToastUtil;
import com.yi.suprise.view.MainActivity;
import com.yi.yilib.Callback;
import com.yi.yilib.mvp.YiPresenter;
import com.yi.yilib.mvp.YiView;

import java.util.ArrayList;

/**
 * Created by zhaoyi on 2016/12/9.
 */

public class MainPresenter implements YiPresenter {
    private YiView<ArrayList<MainModle>> view;
    private MainResponse response;

    public MainPresenter(YiView view) {
        this.view = view;
        response = new MainResponse();
    }

    @Override
    public void onCreate() {
        response.getData(new Callback<MainResponse>() {
            @Override
            public void onResult(MainResponse mainResponse) {
                if (mainResponse.getStatus() > 0){
                    ArrayList<MainModle> modles = mainResponse.getModles();
                    if (modles.size()>0){
                        view.setData(modles);
                    }else {
                        view.noData();
                    }
                }else {
                    view.error();
                }
            }
        });
    }

    @Override
    public void performOnClick(int id) {

    }

    @Override
    public void onStop() {

    }
}
